/*
 * @Description:
 * @version: 1.0.0
 * @Author: YinJianFeng
 * @Date: 2024-03-29 10:15:27
 */
/**
 * @author YinJianFeng
 * @since 2024-01-10
 */

import { ContextMenu, IContextMenu, MenuItem, STATE } from '@amcax/base';
import { dimPicker } from '../../commands/sketch/cmd-render-pick/dimPick';
import { sketchEventCenter } from '../../events/SketchEventCenter';
import { deleteSketchCruve } from '@app-cad/common/utils';

function Component(props: { id: string }) {
  function handleItemClick() {
    deleteSketchCruve();
  }

  return (
    <ContextMenu id={props.id}>
      <MenuItem
        id='delete'
        onClick={handleItemClick}
      >
        删除
      </MenuItem>
    </ContextMenu>
  );
}

const show = (): boolean => {
  if (sketchEventCenter().state === 'sleeping') {
    return false;
  }
  const selectedModels = dimPicker().getSelectedObj();
  if (sketchEventCenter().state !== STATE.DEFAULT) {
    return false;
  }
  return selectedModels.length > 0;
};

export const DimContextMenu: IContextMenu = {
  id: 'dimContextMenu',
  show,
  render: (id: string, params?) => (
    <Component
      id={id}
      key={`next-cad-context-menu-${id}`}
      {...params}
    />
  ),
};
